feat: capture pre-init Python environment in init telemetry#6534
Conversation
Snapshot virtualenv state and presence of pyproject.toml/requirements.txt before template scaffolding runs so the "init" event reflects the user's actual starting environment, not files the template created.
Greptile SummaryThis PR adds a
Confidence Score: 5/5Safe to merge — the change is additive telemetry only and does not affect application init logic. The snapshot is captured before scaffolding, passed through the existing properties merge path in _prepare_event, and is never persisted or used in any control flow. reflex/utils/telemetry.py — the conda detection gap in is_in_virtualenv is worth a second look before the data is relied upon for analysis. Important Files Changed
Sequence DiagramsequenceDiagram
participant User
participant initialize_app
participant get_init_environment
participant Filesystem
participant telemetry_send
User->>initialize_app: reflex init
initialize_app->>initialize_app: check Config.FILE exists (reinit guard)
initialize_app->>get_init_environment: capture pre-scaffolding state
get_init_environment->>get_init_environment: is_in_virtualenv() [sys.prefix, VIRTUAL_ENV]
get_init_environment->>Filesystem: Path("pyproject.toml").exists()
get_init_environment->>Filesystem: Path("requirements.txt").exists()
get_init_environment-->>initialize_app: "{in_virtualenv, has_pyproject_toml, has_requirements_txt}"
initialize_app->>initialize_app: scaffold template
initialize_app->>telemetry_send: "send("init", template=…, properties=init_environment)"
telemetry_send-->>User: async fire-and-forget to PostHog
Reviews (2): Last reviewed commit: "Merge remote-tracking branch 'upstream/m..." | Re-trigger Greptile |
# Conflicts: # tests/units/test_telemetry.py
|
@greptile |
Also short-circuit get_init_environment() when telemetry is disabled and attach the snapshot to reinit events so reinitialized projects are captured alongside fresh inits.
Snapshot virtualenv state and presence of pyproject.toml/requirements.txt before template scaffolding runs so the "init" event reflects the user's actual starting environment, not files the template created.
All Submissions:
Type of change
Please delete options that are not relevant.
New Feature Submission:
Changes To Core Features:
fixes ENG-9476